package com.zhixinglu.spring.boot.rocketmq.client.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

/**
 * <p>
 * RocketMqController
 * </p>
 *
 * @author weixin
 * @date 2023/2/27 15:23
 */
@Slf4j
@RestController
public class RocketMqController {

    private static final String TOPIC = "DemoTopic";
    private static final String TAGS = "glmapperTags";

    @Autowired
    private DefaultMQProducer defaultMqProducer;

    @GetMapping("send")
    public String test() throws Throwable {
        Message msg = new Message(TOPIC, TAGS, ("Say Hello RocketMQ to Glmapper").getBytes(StandardCharsets.UTF_8));
        // 调用客户端发送消息
        SendResult sendResult = defaultMqProducer.send(msg);
        log.info("sendResult: {}.",sendResult);
        return "SUCCESS";
    }

}
